﻿/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DaveSexton.DocProject.Sandcastle
{
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "x")]
	public sealed partial class Help1xProjectEditorDialog : Form
	{
		#region Public Properties
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "x")]
		public Help1xProject Help1xProject
		{
			get
			{
				return helpProject;
			}
		}
		#endregion

		#region Private / Protected
		private static readonly Guid DialogGuid = new Guid("0DF6174C-4D5E-4577-BFFD-F7F707788FA6");

		private readonly Help1xProject helpProject;
		private readonly DialogSettings<Help1xProjectEditorDialog> dialogSettings;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="Help1xProjectEditorDialog" /> class.
		/// </summary>
		public Help1xProjectEditorDialog(Help1xProject helpProject)
			: this()
		{
			if (helpProject == null)
				throw new ArgumentNullException("helpProject");

			this.helpProject = helpProject;

			dialogSettings = new DialogSettings<Help1xProjectEditorDialog>(this, DialogGuid);
			dialogSettings.Load();

			DataBind();
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="Help1xProjectEditorDialog" /> class.
		/// </summary>
		private Help1xProjectEditorDialog()
		{
			InitializeComponent();

			filesDataGridView.AutoGenerateColumns = false;
		}
		#endregion

		#region Methods
		private void DataBind()
		{
			outputEnabledCheckBox.DataBindings.Add("Checked", helpProject, "OutputEnabled");
			binaryTocCheckBox.DataBindings.Add("Checked", helpProject, "BinaryToc");
			binaryIndexCheckBox.DataBindings.Add("Checked", helpProject, "BinaryIndex");
			autoIndexCheckBox.DataBindings.Add("Checked", helpProject, "AutomaticIndex");
			fullTextSearchCheckBox.DataBindings.Add("Checked", helpProject, "FullTextSearch");
			displayProgressCheckBox.DataBindings.Add("Checked", helpProject, "DisplayProgressDuringBuild");
			
			defaultWindowTextBox.DataBindings.Add("Text", helpProject, "DefaultWindow");
			defaultTopicTextBox.DataBindings.Add("Text", helpProject, "DefaultTopic");

			filesDataGridView.DataSource = helpProject.IncludeFiles;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
					components.Dispose();

				dialogSettings.Dispose();
			}
			base.Dispose(disposing);
		}
		#endregion

		#region Event Handlers
		protected override void OnFormClosing(FormClosingEventArgs e)
		{
			base.OnFormClosing(e);

			if (!e.Cancel)
				dialogSettings.Save();
		}

		private void okButton_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
		}
		#endregion
	}
}
